package utils;

import java.util.List;

import javax.swing.JList;

import modelInterfaces.IRecommenderSetup;
import modelInterfaces.ITest;

public class Validations {
	
	/**
	 * Checks whether the test is valid for your writing, you must have associated 
	 * outcomes, a file name and directory to be saved.
	 * 
	 * @param test      Test to be evaluate
	 * @return
	 */
	public static boolean isValidTestWrite(ITest test){
		if(test.getDirPath()==null 	|| test.getOutputFile()==null 
				|| test.getResultMap()==null || test.getResultMap().isEmpty()){
			return false;
		}
		return true;
	}
	
	/**
	 * Checks if the test is valid to read, should have a directory name and file to load.
	 * 
	 * @param test      Test to be evaluate
	 * @return
	 */
	public static boolean isValidTestLoad(ITest test){
		if(test.getDirPath()==null 	|| test.getOutputFile()==null){
			return false;
		}
		return true;
	}
	
	/**
	 * Checks if the test is empty, no algorithms or metrics associated.
	 * 
	 * @param test      Test to be evaluate.
	 * @return
	 */
	public static boolean isNoEmptyTest(ITest test){
		if(test.getAlgorithms().size() == 0 || test.getMetrics().size() == 0 || test.getName().equals("")){
			return false;
		}
		return true;
	}
	
	/**
	 * Checks whether the list contains the test that is given as parameter. if does not 
	 * contain it is valid to add to the list.
	 * 
	 * @param testList      Test list.
	 * @param test      Test to verify existence in list.
	 * @return
	 */
	public static boolean isValidAddTest(List<ITest> testList, ITest test){
		if(testList.contains(test)){
			return false;
		}
		return true;
	}

	public static boolean isValidList(JList listUsers) {
		return !listUsers.isSelectionEmpty();
	}

	public static boolean isValidRunSetup(String itemsAmount, JList listUsers, JList listEventTypes) {		

		if(itemsAmount.equals("") || itemsAmount == null)
		{
			return false;
		}
		
		if (!isNumber(itemsAmount))
		{
			return false;
		}	
		
		if(Integer.valueOf(itemsAmount) <= 0)
		{
			return false;
		}
		
		if(listUsers.isSelectionEmpty())
		{
			return false;
		}
		
		if(listEventTypes.isSelectionEmpty())
		{
			return false;
		}

		return true;
	}
	
	
	public static boolean isNumber(String str)
	{
		for(int i = 0; i<str.length(); i++)
		{
			 if( !Character.isDigit(str.charAt(i)) )
			 {
				 return false;
			 }
		}
		
		return true;
	}
	
	
}
